﻿using Microsoft.Extensions.Logging;
using RBAC.MaHaiBo.Entity;
using RBAC.MaHaiBo.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RBAC.MaHaiBo.Service
{
    public class CityService: ICityService
    {
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<CityService> logger;
        /// <summary>
        /// 市仓储
        /// </summary>
        ICityRepository cityRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="cityRep">市仓储</param>
        public CityService(ILogger<CityService> logger,
         ICityRepository cityRep
         )
        {
            this.logger = logger;
            this.cityRep = cityRep;
        }

        /// <summary>
        /// 市
        /// </summary>
        /// <returns>返回市信息列表</returns>
        public async Task<List<City>> GetCity(int provinceId)
        {
            try
            {
                return await cityRep.GetAsync(p => p.provinceId == provinceId);
            }
            catch (Exception ex)
            {
                logger.LogError("【市服务层】 市信息列表" + ex.Message);
                throw;
            }
        }
    }
}
